/**
 * Copyright &copy; 2012-2016 <a href="https://www.kaaction.com">KAA</a> All rights reserved All rights reserved.
 */
package com.kaaction.modules.test.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.kaaction.common.config.Global;
import com.kaaction.common.persistence.Page;
import com.kaaction.common.web.BaseController;
import com.kaaction.common.utils.StringUtils;
import com.kaaction.modules.test.entity.HqhscProduct;
import com.kaaction.modules.test.service.HqhscProductService;

/**
 * 虎丘婚纱城运营商品Controller
 * @author ZengBiao
 * @version 2017-06-20
 */
@Controller
@RequestMapping(value = "${adminPath}/test/hqhscProduct")
public class HqhscProductController extends BaseController {

	@Autowired
	private HqhscProductService hqhscProductService;
	
	@ModelAttribute
	public HqhscProduct get(@RequestParam(required=false) String id) {
		HqhscProduct entity = null;
		if (StringUtils.isNotBlank(id)){
			entity = hqhscProductService.get(id);
		}
		if (entity == null){
			entity = new HqhscProduct();
		}
		return entity;
	}
	
	@RequiresPermissions("test:hqhscProduct:view")
	@RequestMapping(value = {"list", ""})
	public String list(HqhscProduct hqhscProduct, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<HqhscProduct> page = hqhscProductService.findPage(new Page<HqhscProduct>(request, response), hqhscProduct); 
		model.addAttribute("page", page);
		return "modules/test/hqhscProductList";
	}

	@RequiresPermissions("test:hqhscProduct:view")
	@RequestMapping(value = "form")
	public String form(HqhscProduct hqhscProduct, Model model) {
		model.addAttribute("hqhscProduct", hqhscProduct);
		return "modules/test/hqhscProductForm";
	}

	@RequiresPermissions("test:hqhscProduct:edit")
	@RequestMapping(value = "save")
	public String save(HqhscProduct hqhscProduct, Model model, RedirectAttributes redirectAttributes) {
		if (!beanValidator(model, hqhscProduct)){
			return form(hqhscProduct, model);
		}
		hqhscProductService.save(hqhscProduct);
		addMessage(redirectAttributes, "保存虎丘婚纱城运营商品成功");
		return "redirect:"+Global.getAdminPath()+"/test/hqhscProduct/?repage";
	}
	
	@RequiresPermissions("test:hqhscProduct:edit")
	@RequestMapping(value = "delete")
	public String delete(HqhscProduct hqhscProduct, RedirectAttributes redirectAttributes) {
		hqhscProductService.delete(hqhscProduct);
		addMessage(redirectAttributes, "删除虎丘婚纱城运营商品成功");
		return "redirect:"+Global.getAdminPath()+"/test/hqhscProduct/?repage";
	}

}